﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Peekaboo2008.model;
using System.Data.SqlClient;
using Peekaboo2008.util;

namespace Peekaboo2008.dao
{
    class KhoHangDAO
    {
        public static KhoHangModel getByMaChiNhanh(String _maChiNhanh)
        {
            KhoHangModel model = new KhoHangModel();
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("Ma_chi_nhanh", SqlDbType.Int);
            param[0].Value = _maChiNhanh;

            DataTable tb =  DataUtil.executeStore("sp_KhoHang_GetByMaChiNhanh", param);
            try
            {
                foreach (DataRow dr in tb.Rows)
                {
                    model.ID = dr["ID"].ToString();
                    model.Ten = dr["Ten"].ToString();
                    model.MaLoaiKhoHang = dr["Ma_loai_kho_hang"].ToString();
                    model.GhiChu = dr["Ghi_chu"].ToString();
                    model.MaChiNhanh = dr["Ma_chi_nhanh"].ToString();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace.ToString());
            }
            return model;
        }
    }
}
